package com.ytc.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ytc.model.Book;
import com.ytc.service.BookService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/book")
public class bookController {
    private BookService bookService;

    @RequestMapping("queryBookList")
    public String queryBookList(Model model, @RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum){
        //分页计算分页的提条数以及开始的页数
        PageHelper.startPage(pageNum, 3);
        List<Book> list=bookService.queryBookList();
        PageInfo<Book> pageInfo=new PageInfo<Book>(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("list",list);
        return "book/showBook";

    }
}
